<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of OrderController
 *
 * @author bom
 */
class Cms_OrderController extends My_Controller_Action {

    //put your code here
    public function init() {
        parent::init();
        $this->view->rightModules('right');
        $this->view->soldDealModule('deal_bottom', 0);
        $this->view->visitorCountModule('right');
    }

    public function indexAction() {
        $this->view->errors = $this->_errorMessenger->getMessages();
        $this->_errorMessenger->clearMessages();
    }

    public function viewAction() {
        $order_id = $this->getRequest()->getParam('id') - 1000000;
        $order = $this->loadModel('cms', 'Order');
        $order_item = $this->loadModel('cms', 'OrderItem');
        $shipping = $this->loadModel('checkout', 'ShippingAddress');
        $order_type = $this->loadModel('cms', 'OrderType');

        $this->view->order = $order->fetchRow($order->select()->where('order_id=?', $order_id));
        if(!$this->view->order){
            $this->_errorMessenger->addMessage('Đơn hàng không tồn tại !');
            $redirect_url = $this->getUrl(array("module" => "cms", "controller" => "order", "action" => "index"));
            $this->_redirect($redirect_url);
        }

        $this->view->items = $order_item->fetchAll($order_item->select()->where('order_id=?', $order_id));
        $this->view->shipping = $shipping->fetchRow($shipping->select()->where('address_id=?', $this->view->order->address_id));
        $this->view->order_type = $order_type->fetchRow($order_type->select()->where('order_type_id=?', $this->view->order->order_type_id));
        $subtotal = 0;
        foreach ($this->view->items as $tmp) {
            $subtotal += $tmp->row_total;
        }
        $this->view->subtotal = $subtotal;
    }

}

?>
